<template>
	<el-dialog title="档案归档" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="24">
					<el-form-item label="档案分类" prop="sortId">
						<el-cascader v-model="form.sortId" :options="groups" :props="groupsProps" :show-all-levels="false" clearable style="width: 100%;"></el-cascader>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="归档时间" prop="beginTime">
						<el-date-picker v-model="form.beginTime" placeholder="归档时间" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="到期处置" prop="disposalMethod">
						<sc-select v-model="form.disposalMethod" :params="{code:'disposalMethod'}" :apiObj="$API.archives.archivesDic.getArchivesDicByCode" clearable filterable  style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">确 认</el-button>
		</template>
	</el-dialog>

</template>
<script>
import AttachMenu from "@/views/module/attachMenu.vue";
export default {
	emits: ['success', 'closed'],
	components: {
		AttachMenu,
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			form:{
				recordId:'',
				sortId:'',
				status:'1',
				frameStatus:'0',
				disposalMethod:1,
				storagePeriod:'',
				beginTime:'',
			},
			groups: [],
			groupsProps: {
				label:"name",
				value: "sortId",
				emitPath: false,
				checkStrictly: true
			},
			rules: {
				sortId: [
					{required: true, message: '档案分类不能为空', trigger: 'blur'}
				],
				beginTime:[
					{required: true, message: '归档时间不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
		this.getArchivesSortTree();
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		async getArchivesSortTree(){
			var res = await this.$API.archives.archivesSort.getArchivesSortTree.get();
			this.groups = res.data;
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.archives.archivesRecord.updateArchivesRecord.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.recordId = data.recordId
			this.form.sortId = data.sortId
			this.form.disposalMethod = data.disposalMethod
			this.form.beginTime = data.beginTime;
			this.form.storagePeriod = data.storagePeriod
		}
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
